home *** CD-ROM | disk | FTP | other *** search
- // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
- /* $Id: COMLINK.cpp 1.4 1997/04/05 02:39:22 damien Exp $ */
-
- ////////////////////////////////////////////////////////////////////////
- // Motion Link Example //
- //--------------------------------------------------------------------//
- // Implementation of the ScrewLink Interface //
- ////////////////////////////////////////////////////////////////////////
-
- #include "math.h"
-
- #ifndef __COMLINK__
- #include "COMLink.h"
- #endif
-
- #ifndef __LINKDLL__
- #include "LinkDLL.h"
- #endif
-
- #ifndef __3DCOFAIL__
- #include "3DCoFail.h"
- #endif
-
- const NUM3D kTwoPi = 3.14159265358979323846 * 2.0;
-
- #undef INTERFACE
- #define INTERFACE ScrewLink
- // Constructor / Destructor of the C++ Object :
- ScrewLink::ScrewLink() {
- fCRef=0; // Reference Counter
- // Data initialisation :
- fData.fAxis = kAxisZ;
- fData.fStep = 1.0;
- fData.fFreedomValue = 0.0;
- }
-
- ScrewLink::~ScrewLink() {
- global_count_Obj--;
- }
-
- // IUnknown Interface :
- HRESULT ScrewLink::QueryInterface(THIS_ REFIID riid,LPVOID* ppvObj) {
- *ppvObj=NULL;
-
- // The ScrewLink knows the interfaces of the parent Objects
- if (IsEqualIID(riid, IID_IUnknown))
- *ppvObj=(LPVOID)this;
- else if (IsEqualIID(riid, IID_I3DExMotionLink))
- *ppvObj=(LPVOID)this;
- else if (IsEqualIID(riid, IID_I3DExDataExchanger))
- *ppvObj=(LPVOID)this;
- else if (IsEqualIID(riid, IID_I3DExtension))
- *ppvObj=(LPVOID)this;
-
- // we must add reference if we return an interface
- if (*ppvObj!=NULL) {
- ((LPUNKNOWN)*ppvObj)->AddRef();
- return NOERROR;
- }
- else {
- return ResultFromScode(E_NOINTERFACE);
- }
- }
-
- ULONG ScrewLink::AddRef(THIS) {
- return fCRef++;
- }
-
- ULONG ScrewLink::Release(THIS) {
- ULONG UnreleaseObject=fCRef--;
-
- if (fCRef==0)
- delete this; // No reference left, so destroy the object
-
- return UnreleaseObject;
- // local variable used, because fCRef can be destroyed before.
- }
-
- // I3DExtension methods :
- I3DExtension* ScrewLink::Clone(THIS) {
- ScrewLink* theClone = new ScrewLink;
- if (theClone) {
- theClone->AddRef();
- theClone->fData=fData; // copy the ScrewLinkData
- }
- return theClone;
- }
-
- HRESULT ScrewLink::ShellUtilitiesInit(THIS_ IShUtilities* shellUtilities) {
- InitCoFailure(shellUtilities);
- return NOERROR;
- }
-
- // I3DExDataExchanger methods :
- ExtensionDataMap* ScrewLink::GetExtensionDataMap(THIS) {
- return NULL;
- }
-
- void* ScrewLink::GetExtensionDataBuffer(THIS) {
- return &fData; // used by the shell to set the new parameters
- }
-
- HRESULT ScrewLink::ExtensionDataChanged(THIS) {
- return NOERROR;
- }
-
- HRESULT ScrewLink::HandleEvent(THIS_ ULONG SourceID) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- short ScrewLink::GetResID(THIS) {
- return 141; // this is the view ID in the resource file.
- }
-
- // I3DExMotionLink methods :
- short ScrewLink::GetNbrFreedom(THIS) {
- return 1;
- }
-
- HRESULT ScrewLink::GetFreedomRange(THIS_ short index, NUM3D* min, NUM3D* max) {
- if (index==1) {
- *min = -32767.0;
- *max = 32767.0;
- }
- return NOERROR;
- }
-
- HRESULT ScrewLink::IncrementFreedomValue(THIS_ short index, NUM3D* increment) {
- if (index==1) {
- fData.fFreedomValue += *increment;
- }
- return NOERROR;
- }
-
-
-
- HRESULT ScrewLink::GetTransform(THIS_ TRANSFORM3D* transform) {
- short u,v,w;
- NUM3D alpha,cosa,sina;
- NUM3D altitude;
- NUM3D m33[3][3];
-
- altitude = fData.fFreedomValue * fData.fStep;
- alpha = fData.fFreedomValue * kTwoPi;
-
- if (fData.fAxis==kAxisX) {
- u=1;v=2;w=0;
- }
- else if (fData.fAxis==kAxisY) {
- u=2;v=0;w=1;
- }
- else if (fData.fAxis==kAxisZ) {
- u=0;v=1;w=2;
- }
- transform->fT[u] = 0.0;
- transform->fT[v] = 0.0;
- transform->fT[w] = altitude;
- sina=sin(alpha);
- cosa=cos(alpha); //QuickSinCos(alpha,sina,cosa);
- m33[u][u]=cosa; m33[u][v]=sina; m33[u][w]=0.0;
- m33[v][u]=-sina; m33[v][v]=cosa; m33[v][w]=0.0;
- m33[w][u]=0.0; m33[w][v]=0.0; m33[w][w]=1.0;
- transform->fR = *(MATRIX3D*)&m33;
-
- return NOERROR;
- }
-
- HRESULT ScrewLink::GetTransformPartialDerivate(THIS_ short index, TRANSFORM3D* transform) {
- short u,v,w;
- NUM3D alpha,cosa,sina;
- NUM3D m33[3][3];
- if (fData.fAxis==kAxisX) {
- u=1;v=2;w=0;
- }
- else if (fData.fAxis==kAxisY) {
- u=2;v=0;w=1;
- }
- else if (fData.fAxis==kAxisZ) {
- u=0;v=1;w=2;
- }
- if (index==1) {
- transform->fT[u] = 0.0;
- transform->fT[v] = 0.0;
- transform->fT[w] = fData.fStep;
- alpha = kTwoPi * fData.fFreedomValue;
- sina=sin(alpha);
- cosa=cos(alpha); //QuickSinCos(alpha,sina,cosa);
- m33[u][u]=-kTwoPi * sina;
- m33[u][v]=kTwoPi * cosa;
- m33[u][w]=0.0;
- m33[v][u]=-kTwoPi * cosa;
- m33[v][v]=-kTwoPi * sina;
- m33[v][w]=0.0;
- m33[w][u]=0.0;
- m33[w][v]=0.0;
- m33[w][w]=0.0;
- transform->fR = *(MATRIX3D*)&m33;
-
- }
- return NOERROR;
- }
-